package com.panopset.refactorsf;

import javax.swing.JMenuItem;

import com.panopset.java.Version;

/**
 *
 * @author Karl Dinwiddie
 *
 * @param <T>
 *            Object to store in the menu item.
 */
public final class StorageMenuItem<T> extends JMenuItem
    implements Comparable<StorageMenuItem<T>> {

    /**
     * Item storage.
     */
    private final T itemStorage;

    /**
     * @return Item storage.
     */
    public T getItemStorage() {
        return itemStorage;
    }

    /**
     * @param value
     *            Item to store.
     */
    public StorageMenuItem(final T value) {
        super(value.toString());
        itemStorage = value;
    }

    @Override
    public int compareTo(final StorageMenuItem<T> o) {
        return getText().compareTo(o.getText());
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof StorageMenuItem<?>)) {
            return false;
        }
        return getText().equals(
                ((StorageMenuItem<?>) obj).getText());
    }

    @Override
    public int hashCode() {
        return getText().hashCode();
    }

    /**
     * Serial version id.
     */
    private static final long serialVersionUID = Version.UNI_VERSION;
}
